package action.adapter;

import java.util.ArrayList;

import action.newelifile.FtpActivity;
import action.newelifile.R;
import action.pojo.FtpConnect;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FtpFileAdapter extends BaseAdapter{
	Context context;
	ArrayList<FtpConnect> arrayList;
	ViewHolder holder;
	int layoutid;
	
	public FtpFileAdapter(FtpActivity context,int textViewResourceId,ArrayList<FtpConnect> arrayList){
		this.context=context;
		this.arrayList=arrayList;
		this.layoutid=textViewResourceId;
		
	}
	public FtpFileAdapter(Context context,int textViewResourceId,ArrayList<FtpConnect> arrayList){
		this.context=context;
		this.arrayList=arrayList;
		this.layoutid=textViewResourceId;
		
	}
	@Override
	public int getCount() {
		return arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayList.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final FtpConnect ftpConnect = arrayList.get(position);
		if(convertView==null){
			holder = new ViewHolder();
			LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=layoutInflater.inflate(layoutid, parent,false);
			holder.txtname = (TextView) convertView.findViewById(R.id.name);
			holder.txtinfo = (TextView)convertView.findViewById(R.id.info);
			holder.imiIcon = (ImageView) convertView.findViewById(R.id.icon);
			holder.imiCheck =(ImageView)convertView.findViewById(R.id.checked);
			holder.imiFavorite = (ImageView)convertView.findViewById(R.id.favorite);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		
		if(ftpConnect.getHostname()!=null && !ftpConnect.getHostname().equals("")){
			holder.txtname.setText(ftpConnect.getHostname());
			holder.imiIcon.setImageResource(R.drawable.ftpserver);
		}

		return convertView;
	}
	
	public static class ViewHolder {
		TextView txtname,txtinfo;
		ImageView imiIcon,imiCheck,imiFavorite;
    }
	

}
